// Global
var Site_Global = {
	w:$(window).width(),
	h:$(window).height(),
	isIE6:0
};
(function(){
	if($.browser.msie && ($.browser.version == "6.0") && !$.support.style){
		return Site_Global.isIE6 = 1;
	}
})();
window.onresize = function(){
	Site_Global.w = $(window).width();
	Site_Global.h = $(window).height();
}

//背景遮罩
var Pop_mask = {
	Mask : $('#js-pop-mask'),
	
	init : function(){
		$('body').append('<div id="js-pop-mask"></div>');
		Pop_mask.Mask = $('#js-pop-mask');

		if(Site_Global.isIE6){
			Pop_mask.init = function(){
				Pop_mask.Mask.css({'width':$(document).width(), 'height':$(document).height()})
			}
		}else{
			Pop_mask.init = function(){
				Pop_mask.Mask.css({'width':Site_Global.w, 'height':Site_Global.h});
			}
		}
		Pop_mask.init();
	},
	
	run : function(_opt){
		if( !Pop_mask.Mask.lenght){
			Pop_mask.init();
		}
		Pop_mask.run =  function(_opt){
			if(_opt == 'show'){
				$('html').css('overflow','hidden');
				Pop_mask.Mask.show();
			}else{
				$('html').css('overflow','auto');
				Pop_mask.Mask.hide();		
			}
		}
		Pop_mask.run(_opt);		
	}
	
}
$(window).on('resize',Pop_mask.init);


//关闭所有弹窗
function clearHiPop(){
	var pop = $('.js-pop-group');
	pop.hide();
}

//弹窗
function HiPop(_opt){
	var
		$this = this ,
		box = $(_opt.obj) ,
		box_w = box.width() ,
		box_h = box.height() ;

	function pos(){
		pos_x = (Site_Global.w - box_w)/2;
		pos_y = (Site_Global.h - box_h)/2;
		if(Site_Global.isIE6){
			pos_x += $(window).scrollLeft();
			pos_y += $(window).scrollTop();
		}
		box.css({"left":pos_x, "top":pos_y});
	}
			
	this.open = function(t){
		pos();
		box.fadeIn(300);
		$(window).on('resize',pos);
		if(!t) Pop_mask.run('show');
	}
	
	this.close = function(s){
		box.fadeOut(200);
		$(window).off('resize',pos);
		if(!s) Pop_mask.run('hide');
	}
	box.find('.js-pop-close').on('click',function(){
		$this.close();
	});
	
	if(_opt.init){
		this.open();
	}

}